package com.school.movie.business.web.controller;

import com.school.movie.business.web.model.vo.SysLogVo;
import com.school.movie.common.bean.PageBean;
import com.school.movie.service.imp.SysLogServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/log")
public class SysLogController {

    @Autowired
    SysLogServiceImp logService;

    @RequestMapping("/list")
    public String list(SysLogVo log, PageBean pager, HttpSession session, ModelMap map) {

        if (log == null || log.getUserName() == null) {
            if (session.getAttribute("log") != null) {
                log = (SysLogVo) session.getAttribute("log");
            }
        } else {
            session.setAttribute("log", log);
        }

        int cnt = logService.count(log);
        pager.setTotalRows(cnt);
        List<SysLogVo> logList = logService.list(log, pager);
        pager.setData(logList);
        map.addAttribute("pager", pager);
        map.addAttribute("log", log);
        String[] logTypes = {"新增", "修改", "删除", "登陆", "修改密码", "延期"};
        map.addAttribute("logTypes", logTypes);
        return "reportLog";
    }
}
